Skip to main content

FrontFetchAsync

Wolfram Kernel
Execution environment
Notebook`Editor`Kernel`FrontSubmitService`
Context

asynchronously evaluates (aka FrontSubmit) and fetches the resulting expression back to the Wolfram Kernel from the frontend (browser)

FrontFetchAsync[expr_, opts___] _Promise

and returns Promise object.

Options

"Window"

specifies a window socket, to which an expression will be sent. Use CurrentWindow to fetch a window object from the evaluation context explicitly.

"Format"

The default expression form used to import raw data acquired from the frontend. It effectively applies ImportString on raw JSON data. The possible values

  • "JSON" (the default)
  • "ExpressionJSON"
  • "Raw" bypasses parser and returns a string

Usage with FrontInstanceReference

Using an extension FrontInstanceReference, one can execute an expression in the context of a specified container and fetch the result back

FrontFetchAsync[expr_, m_FrontInstanceReference, opts___] _Promise

See examples on FrontSubmit

Examples

To read the selected text from a cell and print it to another cell

With[{cell = ResultCell[]},
EventHandler[InputButton["Read selected text"], Function[Null,

Then[FrontFetchAsync[FrontEditorSelected["Get"]], Function[result,
CellPrint[result
, "After"->cell];
]
]
]]
]

or to read a clipboard of a user

With[{cell = ResultCell[]},
EventHandler[InputButton["Read clipboard"], Function[Null,

Then[FrontFetchAsync[ReadClipboard[]], Function[result,
CellPrint[result
, "After"->cell];
]
]
]]
]